// core/speed_rs/src/lib.rs
use pyo3::prelude::*;
use tokio::net::TcpStream;
use std::time::Instant;

#[pyfunction]
async fn rs_async_ping(host: &str, port: u16) -> PyResult<f64> {
    let start = Instant::now();
    match TcpStream::connect((host, port)).await {
        Ok(_) => Ok(start.elapsed().as_secs_f64() * 1000.0), // 毫秒
        Err(_) => Ok(f64::INFINITY)
    }
}

#[pymodule]
fn speed_rs(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(rs_async_ping, m)?)?;
    Ok(())
}